package com.bjpowernode.crm.workbench.service.impl;

import com.bjpowernode.crm.settings.service.UserService;
import com.bjpowernode.crm.workbench.domain.TranRemark;
import com.bjpowernode.crm.workbench.mapper.TranRemarkMapper;
import com.bjpowernode.crm.workbench.service.TranRemarkService;
import lombok.Getter;
import lombok.Setter;

import com.bjpowernode.crm.workbench.service.TranRemarkService;

import java.util.List;

@Getter
@Setter
public class TranRemarkServiceImpl implements TranRemarkService {

    /**
     * 访问交易备注数据
     */
    private TranRemarkMapper tranRemarkMapper;

    /**
     * 处理用户相关业务
     */
    private UserService userService;

    @Override
    public void addTranRemarks(List<TranRemark> tranRemarks) {
        this.tranRemarkMapper.insertTranRemarks(tranRemarks);
    }

    @Override
    public List<TranRemark> queryTranRemarksByTranId(String tranId) {
        List<TranRemark> tranRemarks = this.tranRemarkMapper.selectTranRemarksByTranId(tranId);

        //数据库中存放的是创建者、最后一个编辑者的 id ，页面需要的是他们的名称
        for (TranRemark tranRemark : tranRemarks) {
            tranRemark.setCreateBy(this.userService.queryNameById(tranRemark.getCreateBy()));
            tranRemark.setEditBy(this.userService.queryNameById(tranRemark.getEditBy()));
        }

        return tranRemarks;
    }

}
